package com.htiiot.sparkpredict.controller;

import com.alibaba.fastjson.JSONObject;
import com.htiiot.common.config.imp.ConfigClient;
import com.htiiot.sparkpredict.bean.PredictData;
import com.htiiot.sparkpredict.tool.LinearMetricPredict;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :chensi
 */
@RestController
public class PredictController {
    private Logger log = Logger.getLogger(PredictController.class);
    private String modelPath = ConfigClient.instance().get("metricpredict","model.path");
    @RequestMapping("/predict/{metricId}")
    public String predict(@PathVariable int metricId){

        PredictData[] result = LinearMetricPredict.predict(modelPath, metricId);
        return JSONObject.toJSONString(result);
    }
}
